/*
 * comlan
 */

package com.promfy.dialog.anim;

import java.util.Timer;
import java.util.TimerTask;

import com.promfy.R;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.AnimationDrawable;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class AnimDialog extends Dialog{

	private ImageView image;
	private AnimationDrawable animationDrawable;
	private Timer timer;
	
	
	public AnimDialog(Context context, int theme) {
		super(context, theme);
		setContentView(R.layout.anim_dialog_view);
		image = (ImageView) findViewById(R.id.image);
		image.setBackgroundResource(R.anim.frame_animation); 
		animationDrawable = (AnimationDrawable) image.getBackground(); 
		
		setOnShowListener(new OnShowListener() {
			
			@Override
			public void onShow(DialogInterface dialog) {
				if(animationDrawable != null){
					animationDrawable.start();
				}
			}
		});
	}



	@Override
	public void show() {
		
		super.show();
		if(timer != null) {
			timer.cancel();
			timer = null;
		}
		timer = new Timer();
		timer.schedule(new TimerTask() {
			
			@Override
			public void run() {
				if(animationDrawable != null){
					animationDrawable.stop(); 
				}
				AnimDialog.this.dismiss();
			}
		}, 1000 * 3);
	}
	
}
